﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace Script.UI.Component
{
    [RequireComponent(typeof(Toggle))]
    public class ToggleData : MonoBehaviour
    {
        public string data;
        public Action<ToggleData, bool> callback;

        protected bool _inited = false;
        protected void Awake()
        {
            Init();
        }

        protected void Init()
        {
            if (_inited)
            {
                return;
            }

            _inited = true;
            gameObject.GetComponent<Toggle>().onValueChanged.AddListener(OnValueChanged);
        }

        public void OnValueChanged(bool bActive)
        {
            callback?.Invoke(this, bActive);
        }
    }
}
